package com.ruoyi.ylyx.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ylyx.domain.YlyxMessage;
import com.ruoyi.ylyx.service.IYlyxMessageService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 留言管理Controller
 * 
 * @author ruoyi
 * @date 2021-02-24
 */
@Controller
@RequestMapping("/ylyx/message")
public class YlyxMessageController extends BaseController
{
    private String prefix = "ylyx/message";

    @Autowired
    private IYlyxMessageService ylyxMessageService;

    @RequiresPermissions("ylyx:message:view")
    @GetMapping()
    public String message()
    {
        return prefix + "/message";
    }

    /**
     * 查询留言管理列表
     */
    @RequiresPermissions("ylyx:message:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(YlyxMessage ylyxMessage)
    {
        startPage();
        List<YlyxMessage> list = ylyxMessageService.selectYlyxMessageList(ylyxMessage);
        return getDataTable(list);
    }

    /**
     * 导出留言管理列表
     */
    @RequiresPermissions("ylyx:message:export")
    @Log(title = "留言管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(YlyxMessage ylyxMessage)
    {
        List<YlyxMessage> list = ylyxMessageService.selectYlyxMessageList(ylyxMessage);
        ExcelUtil<YlyxMessage> util = new ExcelUtil<YlyxMessage>(YlyxMessage.class);
        return util.exportExcel(list, "message");
    }

    /**
     * 新增留言管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存留言管理
     */
    @RequiresPermissions("ylyx:message:add")
    @Log(title = "留言管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(YlyxMessage ylyxMessage)
    {
        return toAjax(ylyxMessageService.insertYlyxMessage(ylyxMessage));
    }

    /**
     * 修改留言管理
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        YlyxMessage ylyxMessage = ylyxMessageService.selectYlyxMessageById(id);
        mmap.put("ylyxMessage", ylyxMessage);
        return prefix + "/edit";
    }

    /**
     * 修改保存留言管理
     */
    @RequiresPermissions("ylyx:message:edit")
    @Log(title = "留言管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(YlyxMessage ylyxMessage)
    {
        return toAjax(ylyxMessageService.updateYlyxMessage(ylyxMessage));
    }

    /**
     * 删除留言管理
     */
    @RequiresPermissions("ylyx:message:remove")
    @Log(title = "留言管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(ylyxMessageService.deleteYlyxMessageByIds(ids));
    }

    /**
     * 禁用
     */
    @RequiresPermissions("ylyx:message:list")
    @PostMapping("/dealMessage")
    @ResponseBody
    public AjaxResult dealMessage(String id)
    {
        YlyxMessage ylyxMessage = new YlyxMessage();
        ylyxMessage.setId(id);
        ylyxMessage.setMessageStatus("已处理");
        return toAjax(ylyxMessageService.updateYlyxMessage(ylyxMessage));
    }
}
